import 'package:flutter/material.dart';
import 'package:wuliu01/TabBarPage/MinePage.dart';
import 'package:wuliu01/TabBarPage/Minemess.dart';
import 'package:wuliu01/TopTab/TopTabBarPage.dart';

class Tabbarpage extends StatefulWidget {
  const Tabbarpage({super.key});

  @override
  State<Tabbarpage> createState() => _TabbarpageState();
}

class _TabbarpageState extends State<Tabbarpage> {
  //当前选中页面对应的索引
  int currentIndex = 0;
  //底部TabBar数据
  List tabBarList = [
    {
      "title": "任务",
      //未选中
      "default": "assets/ic_tab_btn_task.png",
      //选中
      "active": "assets/ic_tab_btn_task.png",
    },
    {
      "title": "消息",
      "default": "assets/ic_tab_btn_mess_nor.png",
      "active": "assets/ic_tab_btn_mess_nor.png",
    },
    {
      "title": "我的",
      "default": "assets/ic_tab_btn_mine_nor.png",
      "active": "assets/ic_tab_btn_mine_nor.png",
    },
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: IndexedStack(
          index: currentIndex,
          children: [TopTabBarPage(), Minemess(), Minepage()],
        ),
      ),
      //底部导航条
      bottomNavigationBar: BottomNavigationBar(
        //设置底部导航样式
        type: BottomNavigationBarType.fixed,
        items: barItemList(),
        currentIndex: currentIndex,
        //选中时的颜色
        selectedItemColor: const Color.fromARGB(255, 232, 48, 69),
        //没选中的颜色
        unselectedItemColor: Colors.black,
        //点击就赋值
        onTap: (index) {
          setState(() {
            currentIndex = index;
          });
        },
      ),

      //
    );
  }

  //提供一个底部导航的按钮
  List<BottomNavigationBarItem> barItemList() {
    List<BottomNavigationBarItem> items = [];
    for (var item in tabBarList) {
      items.add(
        BottomNavigationBarItem(
          icon: Image.asset(item['default'], width: 32, height: 32), //未选中
          activeIcon: Image.asset(
            item['active'],
            width: 32,
            height: 32,
            color: Colors.red,
          ), //选中
          label: item['title'],
        ),
      );
    }
    return items;
  }
}
